package com.itheima.controller;


import domain.User;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    //localhost/user/rp1?name=???&age=???
    @RequestMapping("/rp1")
    public String requestParam1(String name,int age){
        System.out.println(name+","+age);
        return "req2.jsp";
    }

    //localhost/user/rp2?userName=aaa
    @RequestMapping("rp2")
    public String rp2(@RequestParam(value = "userName",required = true)String name){
        System.out.println(name);
        return "req2.jsp";
    }

    //localhost/user/rp3?name=a&age=2
    @RequestMapping("rp3")
    public String rp3(User user){
        System.out.println(user);
        return "req2.jsp";
    }

    //localhost/user/rp4?name=aaa&age=1
    @RequestMapping("rp4")
    public String rp4(User user,int age){
        System.out.println("用户名="+user+", 年龄="+age);
        return "req2.jsp";
    }

    //localhost/user/rp5?address.city=a
    @RequestMapping("rp5")
    public String rp5(User user){
        System.out.println(user .getAddress().getCity());
        return "req2.jsp";
    }

    //localhost/user/rp6?nick=a&nick=b&nick=c
    @RequestMapping("rp6")
    public String rp6(User user){
        System.out.println(user);
        return "req2.jsp";
    }

    //localhost/user/rp7?addresses[0].city=a&addresses[1].province=b
    @RequestMapping("rp7")
    public String rp7(User user){
        System.out.println(user.getAddresses());
        return "req2.jsp";
    }

    //localhost/user/rp8?addressMap['a'].city=aaa&addressMap['b'].province=bbb
    @RequestMapping("rp8")
    public String rp8(User user){
        System.out.println(user.getAddressMap());
        return "req2.jsp";
    }

    //localhost/user/rp9?nick=a&nick=b
    @RequestMapping("rp9")
    public String rp9(String[] nick){
        System.out.println(nick[0]+","+nick[1]);
        return "req2.jsp";
    }

    //localhost/user/rp10?nick=a&nick=b
    @RequestMapping("rp10")
    public String rp10(@RequestParam("nick") List<String> ck){
        System.out.println(ck);
        return "req2.jsp";
    }

    //localhost/user/rp11?date=2001-01-01
    @RequestMapping("rp11")
    public String rp11(@DateTimeFormat(pattern = "yyyy-MM-dd")Date date){
        System.out.println(date);
        return "req2.jsp";
    }

    //localhost/user/rp12?（Parse内的任意格式）
    @RequestMapping("rp12")
    public String rp12(Date date){
        System.out.println(date);
        return "req2.jsp";
    }

    //localhost/user/rpURL1
    @RequestMapping("/rpURL1")
    public String rpURL1(){
        return "req1.jsp";
    }









}
